package TCP;

import java.io.DataInputStream;
import java.io.InputStream;
import java.net.Socket;

public class ServeThread extends Thread{

    private Socket socket;
    public ServeThread(Socket socket){
        this.socket=socket;
    }
    public void run(){

        try {
            InputStream is = socket.getInputStream();
            DataInputStream dis=new DataInputStream(is);
            while(true){
                try {
                    String mgs=dis.readUTF();
                    System.out.println(mgs);
                } catch (Exception e) {
                    System.out.println(socket.getRemoteSocketAddress()+"下线");
                    dis.close();
                    socket.close();
                    break;
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}
